package com.info.zhiduoduo.repository.mapper.company;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.company.CompanyRelationshipListDto;
import com.info.zhiduoduo.repository.entity.company.CompanyRelationship;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 对外项目草稿表 Mapper 接口
 * </p>
 *
 * @author cuichenglong
 * @since 2020-10-09
 */
public interface CompanyRelationshipMapper extends BaseMapper<CompanyRelationship> {

    @Select(" SELECT cr.createtime, c2.compname " +
            " c2.base_tax_rate FROM zdd_company_relationship cr " +
            " LEFT JOIN zdd_company c1 ON c1.compid = cr.main_company_id " +
            " LEFT JOIN zdd_company c2 ON c2.compid = cr.company_id " +
            " WHERE IF(ISNULL(#{companyName}) OR #{companyName} = '', 1=1, c2.compname like '%${companyName}%') ")
    List<CompanyRelationshipListDto> queryCompanyRelationshipList(@Param("companyName") String companyName);

    @Select( " SELECT company_id FROM zdd_company_relationship WHERE main_company_id = #{companyId} " )
    List<Integer> getBindingCompanyId(int companyId);
}
